Ext.extend(demo.module,{
    init: function(){
        var tg = new Ext.fay.ui.TreeGrid({
        fields:[
	      {name:'id',text:'id',header:{hidden:true},ft:'hidden'},
		  {name:'name',text:'模块名称',ft:{allowBlank:false}},
		  {name:'url',text:'js 地址',ft:{allowBlank:false}},
		  {name:'seq',text:'序列',ft:{xtype:'numberfield',allowBlank:false,allowNegative:false,allowDecimals:false}},
		  {name:'parentid',text:'父分类',header:{hidden:true},ft:'hidden'}
        ],
        url:'sysmodulequery',
        tree:{url:'sysmodulenode',rootText:'根部',title:'管理树',listeners:{render:function(t){t.expandAll();}}},
        gridConfig:{title:'各个节点',
          tbar:[
			 	   {text:'添加',iconCls:'add',handler:function(x){
				     this.window.setTitle(x);
				     this.window.show();
				   }},
				   {
				     text:'修改',iconCls:'edit',handler:function(x)
				     {
				       this.window.setTitle(x);
				       this.edit();	 
				     }
				   },
				   {
				     text:'删除',iconCls:'delete',handler:function(x)
				     {				       
				        this.del(function(rs){
				         this.postJson({
				           url:'deletesysmodule',
				           params:{module:{id:rs[0].get("id")}},
				           callback:function(){
				              this.refreshNode();
				           }
				         });
				       });
				     }				   
				   }         
          ]
        }
        });  
        
		 tg.on("save",function(values){
		    if(this.isValid())
		    {		      
		      values.parentid=this.selectedNodeID();
		      this.postJson({
		       url:'savesysmodule',
		       params:{module:values},
		       callback:function(){
		         this.refreshNode();
		       }
		      })
		    }
		 }); 
		 tg.ds.reload();     
		 
		 tg.on("treeclick",function(node){
		    this.ds.baseParams.parentid=node.id;
		    this.ds.reload();		    
		 });		       
        this.main.add(tg.container);
        this.main.doLayout();  
    }
});